package com.tc.nio;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Auther: tianchao
 * @Date: 2022/2/5 19:43
 * @Description:
 */
public class TestFilesWalkFileTree {

    public static void main(String[] args) throws IOException {
        String baseDir = System.getProperty("user.dir");
        AtomicInteger dirCount = new AtomicInteger();
        AtomicInteger fileCount = new AtomicInteger();
        Path path = Paths.get(baseDir);
        Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                System.out.println("=====>dir:"+ dir);
                dirCount.incrementAndGet();
                return super.preVisitDirectory(dir, attrs);
            }

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                System.out.println("====> file:" + file);
                fileCount.incrementAndGet();
                return super.visitFile(file, attrs);
            }
        });
    }
}
